package com.itheima.Classs;

import com.itheima.domain.Student;

import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.Scanner;

public class Test03 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();//创建Student对象集合
        Student s1 = getStudent();
        Student s2 = getStudent();
        Student s3 = getStudent();
        list.add(s1);
        list.add(s2);
        list.add(s3);//添加元素
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);//获取元素并暂存为对象
            System.out.println(stu.getName() + "..." + stu.getAge());//利用get方法访问暂存对象信息并打印
        }

    }

    public static Student getStudent() {//方法中返回值类型为Student,则返回的必须要是该类的对象

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入学生姓名");
        String name = sc.nextLine();
        System.out.println("请输入学生年龄");
        int age = sc.nextInt();
        Student stu = new Student(name, age);
        return stu;
    }

}
